from typing import List


class Solution:
    def countRangeSum(self, nums: List[int], lower: int, upper: int) -> int:
        m = len(nums)

        dp = [[0] * m for _ in range(m)]
        res = 0
        for i in range(m):
            for j in range(i, m):
                if i == j:
                    dp[i][j] = nums[i]
                else:
                    dp[i][j] = dp[i][j - 1] + nums[j]
                if lower <= dp[i][j] <= upper:
                    res += 1

        return res
